package org.coco.mvc.render.impl;

import org.coco.mvc.RequestProcessorChain;
import org.coco.mvc.render.ResultRender;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 页面渲染器
 */
public class ViewResultRender implements ResultRender {

    private Object viewName;

    public ViewResultRender(Object viewName) {
        this.viewName = viewName;
    }

    @Override
    public void render(RequestProcessorChain requestProcessorChain) throws Exception {
        //获取到方法需要返回的页面的值
        HttpServletResponse response = requestProcessorChain.getResponse();
        HttpServletRequest request = requestProcessorChain.getRequest();
        request.getRequestDispatcher("/templates/"+viewName+".html").forward(request,response);
    }
}
